package com.nandi.emergencyinspection.mvp

import com.nandi.emergencyinspection.api.ApiServices
import com.nandi.emergencyinspection.bean.SubmitTaskBean
import com.tbright.ktbaselibrary.extension.response
import kotlinx.coroutines.launch
import okhttp3.MultipartBody

/**
 * @创建者: qingsong
 * @创建时间: 2021/3/25 13:28
 * @描述:
 */
class TaskInfoPresenter : TaskInfoContract.TaskInfoPresenter() {


    override fun acceptTaskAsync(id: String, status: Int) {
        mView?.showLoading()
        mainScope.launch {
            val singlePoetry =
                ApiServices.instance.acceptTaskAsync(id = id, status = status).response()
            if (singlePoetry != null) {
                mView?.showAcceptResult(singlePoetry)
            }
            mView?.hideLoading()
        }
    }

    override fun uploadFile(part: MultipartBody.Part) {
        mView?.showLoading()
        mainScope.launch {
            val singlePoetry =
                ApiServices.instance.uploadFile(file = part).response()
            if (singlePoetry != null) {
                mView?.showUploadFileResult(singlePoetry)
            }
            mView?.hideLoading()
        }
    }

    override fun submitAsync(submitTaskBean: SubmitTaskBean) {
        mView?.showLoading()
        mainScope.launch {
            val singlePoetry =
                ApiServices.instance.submitTaskAsync(submitTaskBean = submitTaskBean).response()
            if (singlePoetry != null) {
                mView?.showSubmitResult(singlePoetry)
            }
            mView?.hideLoading()
        }
    }


}